#pragma once
#ifndef __LIT__SCRIPT__ENGINE__NATIVE_API__HH__
#define __LIT__SCRIPT__ENGINE__NATIVE_API__HH__

#include <Ogre.h>
#include <string>
#include "LitScriptPrereqs.h"
#include "LitScriptEngineOgreWrappers.h"
#include <OgreColourValue.h>

namespace Lit
{
	class NativeScriptAPICoreFuncs
	{
		ScriptEngine * mEng;
		Ogre::SceneManager * mScene;
	public:
		NativeScriptAPICoreFuncs( );
		NativeScriptAPICoreFuncs( ScriptEngine * eng, Ogre::SceneManager * mgr );
		NativeScriptAPICoreFuncs( const NativeScriptAPICoreFuncs& rk );
		~NativeScriptAPICoreFuncs();
			
		static void copyConstructor( const NativeScriptAPICoreFuncs& f, NativeScriptAPICoreFuncs * self ){new(self) NativeScriptAPICoreFuncs( f );}
		Ogre::SceneManager * _getSceneManager(){ return mScene; }
		const Ogre::SceneManager* _getSceneManager() const{ return mScene; }
		void setSceneManager( Ogre::SceneManager * mgr ){ mScene = mgr; }
		
		ScriptWrappers::SceneMgrWrp	getSceneManager( ) const{ return ScriptWrappers::SceneMgrWrp( mScene); } 
		ScriptWrappers::SceneMgrWrp	getSceneManager( const std::string &name ) const{ return ScriptWrappers::SceneMgrWrp( Ogre::Root::getSingleton().getSceneManager(name) ); } 
		ScriptWrappers::SceneMgrWrp	createSceneManager( const std::string &name ) const{ return ScriptWrappers::SceneMgrWrp( Ogre::Root::getSingleton().createSceneManager(name) ); } 
		void destroySceneManager( ScriptWrappers::SceneMgrWrp &mgr ){ if( mgr.mScene ) Ogre::Root::getSingleton().destroySceneManager(mgr.mScene); } 
		
		std::string		getAngelVersion();
		std::string		getVersion();
		void			error( const std::string &msg );
		void			logMessage( const std::string &msg );
		int				messageBox( const std::string &msg, const std::string &title = "Script Info" );
	};
	
	class NativeScriptAPI
	{
	protected:
		void registerOgrePrerequisites(  );
		void registerOgreAngles(  );
		void registerOgreVector2(  );
		void registerOgreVector3(  );
		void registerOgreVector4(  );
		void registerOgreMatrix3(  );
		void registerOgreMatrix4( );
		void registerOgreAABB( );
		void registerOgreQuaternion( );
		void registerOgreColourValue( );
		
		void registerOgreSceneNode( );
		void registerOgreMovableObject( );
		void registerOgreEntity( );
		void registerOgreSceneManager( );

		void registerOgreLog( );
		
		void registerOGRE( Ogre::SceneManager * mgr );
		void registerCoreInputSystem();
		void registerCore( Ogre::SceneManager * mgr );
		
		NativeScriptAPICoreFuncsPtr		mCore;
		ScriptEnginePtr					engine;

		static NativeScriptAPICoreFuncs mBase;
	public:
		static void _setBaseFuncs( const NativeScriptAPICoreFuncs& funcs ){ mBase = funcs; }

		NativeScriptAPI(const ScriptEnginePtr& _engine);
		~NativeScriptAPI();
		
		void bind( Ogre::SceneManager * mgr );

		static NativeScriptAPICoreFuncs getSystem();

		NativeScriptAPICoreFuncsPtr& getCore();
		const NativeScriptAPICoreFuncsPtr& getCore() const;
	};
};

#endif